/*
 * @Author: liuxiao
 * @Date: 2024-02-25 19:32:11
 * @Last Modified by: liuxiao
 * @Last Modified time: 2024-03-03 23:35:06
 * @ 错误基类
 */

interface HttpException {
  msg: string
  errorCode: number
  statusCode: number
  code: number
  result: any
}

/**
 * @description:  http异常类基类
 * @param {*} msg 错误提示信息
 * @param {*} errorCode 错误码(开发人员内部约定)
 * @param {*} statusCode HTTP状态码
 * @param {*} result 错误结果
 * @param {*} code  错误返回码，默认为1
 * @return {*}
 */
class HttpException extends Error {
  constructor(
    result = '',
    msg = '服务器异常',
    errorCode = 10000,
    statusCode = 400,
    code = 1
  ) {
    super()
    this.code = code
    this.msg = msg
    this.errorCode = errorCode
    this.statusCode = statusCode
    this.result = result
  }
}

/**
 * @description:参数异常类
 */
class ParameterException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '参数错误',
    errorCode: number = 10000
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

/**
 * @description: 用户验证异常类
 */
class UserValidationException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '用户名或者密码不正确!',
    errorCode: number = 20000
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

class VideoUploadAuthException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '视频上传凭证错误!',
    errorCode: number = 30000
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

class GetVideoPlayerException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '获取播放凭证或地址错误!',
    errorCode: number = 30001
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}
export {
  HttpException,
  ParameterException,
  UserValidationException,
  VideoUploadAuthException,
  GetVideoPlayerException
}
